package d1130.r211.num06;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Tools {
    //平均分
    public static double getAvg(List<Student> studentList){
        //所有成绩的和
        double sum=0;
        for (Student s : studentList) {
            sum+=s.getScore();
        }
        return sum/studentList.size();
    }
    //找出分数区间的学生
    public static List<Student> getScore(List<Student> studentList,double x,double y){
        List<Student> stu=new ArrayList<>();   //把分数区间的学生放在list集合中   左包含右不包含
        Iterator<Student> iterator=studentList.iterator();
        while (iterator.hasNext()){
            Student student=iterator.next();
            if (student.getScore()>=x&&student.getScore()<y){
                stu.add(student);
            }
        }
        return stu;
    }
}
